{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "934fa564",
   "metadata": {},
   "source": [
    "# pandas数据分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ca9ab721",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1b436017",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>gender</th>\n",
       "      <th>clazz</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1500100001</td>\n",
       "      <td>施笑槐</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>文科六班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1500100002</td>\n",
       "      <td>吕金鹏</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科六班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1500100003</td>\n",
       "      <td>单乐蕊</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科六班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1500100004</td>\n",
       "      <td>葛德曜</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科三班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1500100005</td>\n",
       "      <td>宣谷芹</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科五班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>1500100996</td>\n",
       "      <td>厉运凡</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科三班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>1500100997</td>\n",
       "      <td>陶敬曦</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>1500100998</td>\n",
       "      <td>容昆宇</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>1500100999</td>\n",
       "      <td>钟绮晴</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科五班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>1500101000</td>\n",
       "      <td>符瑞渊</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             id name  age gender clazz\n",
       "0    1500100001  施笑槐   22      女  文科六班\n",
       "1    1500100002  吕金鹏   24      男  文科六班\n",
       "2    1500100003  单乐蕊   22      女  理科六班\n",
       "3    1500100004  葛德曜   24      男  理科三班\n",
       "4    1500100005  宣谷芹   22      女  理科五班\n",
       "..          ...  ...  ...    ...   ...\n",
       "995  1500100996  厉运凡   24      男  文科三班\n",
       "996  1500100997  陶敬曦   21      男  理科六班\n",
       "997  1500100998  容昆宇   22      男  理科四班\n",
       "998  1500100999  钟绮晴   23      女  文科五班\n",
       "999  1500101000  符瑞渊   23      男  理科六班\n",
       "\n",
       "[1000 rows x 5 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student = pd.read_csv(\"../data/students.csv\",names=['id','name','age','gender','clazz'])\n",
    "student"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a2472cce",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 需求1：\n",
    "#   统计所有学生数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b4d03a68",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student.id.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d5f9e2d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 需求2：\n",
    "#   统计各班级学生数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d724a6db",
   "metadata": {},
   "outputs": [],
   "source": [
    "student_cnt = student.groupby(by=['clazz'])['id'].count().reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4112a82a",
   "metadata": {},
   "outputs": [],
   "source": [
    "student_cnt.rename(columns={'id':'cnt'},inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "3be39b7c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>clazz</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>文科一班</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>文科三班</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>文科二班</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>文科五班</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>文科六班</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>文科四班</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>理科一班</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>理科三班</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>理科二班</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>理科五班</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>理科六班</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>理科四班</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   clazz  cnt\n",
       "0   文科一班   72\n",
       "1   文科三班   94\n",
       "2   文科二班   87\n",
       "3   文科五班   84\n",
       "4   文科六班  104\n",
       "5   文科四班   81\n",
       "6   理科一班   78\n",
       "7   理科三班   68\n",
       "8   理科二班   79\n",
       "9   理科五班   70\n",
       "10  理科六班   92\n",
       "11  理科四班   91"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student_cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2ab5768a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 需求3：\n",
    "#   统计学生总分\n",
    "score = pd.read_csv(\"../data/score.txt\",names=['id','subject_id','score'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1bd72807",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1500100001</td>\n",
       "      <td>406</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1500100002</td>\n",
       "      <td>440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1500100003</td>\n",
       "      <td>359</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1500100004</td>\n",
       "      <td>421</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1500100005</td>\n",
       "      <td>395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>1500100996</td>\n",
       "      <td>355</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>1500100997</td>\n",
       "      <td>293</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>1500100998</td>\n",
       "      <td>398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>1500100999</td>\n",
       "      <td>371</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>1500101000</td>\n",
       "      <td>379</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             id  score\n",
       "0    1500100001    406\n",
       "1    1500100002    440\n",
       "2    1500100003    359\n",
       "3    1500100004    421\n",
       "4    1500100005    395\n",
       "..          ...    ...\n",
       "995  1500100996    355\n",
       "996  1500100997    293\n",
       "997  1500100998    398\n",
       "998  1500100999    371\n",
       "999  1500101000    379\n",
       "\n",
       "[1000 rows x 2 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "score_total = score.groupby(by=['id'])['score'].sum().reset_index()\n",
    "score_total"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7d32b0fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 关联学生表\n",
    "# merge\n",
    "# 参数 how 表示用哪种关联方式进行关联\n",
    "#  可以参考官方文档 https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.merge.html\n",
    "student_merge_res = student.merge(score_total,how='inner',on='id') "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "10d186c3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>student_id</th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>gender</th>\n",
       "      <th>clazz</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1500100001</td>\n",
       "      <td>施笑槐</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>文科六班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1500100002</td>\n",
       "      <td>吕金鹏</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科六班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1500100003</td>\n",
       "      <td>单乐蕊</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科六班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1500100004</td>\n",
       "      <td>葛德曜</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科三班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1500100005</td>\n",
       "      <td>宣谷芹</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科五班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>1500100996</td>\n",
       "      <td>厉运凡</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科三班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>1500100997</td>\n",
       "      <td>陶敬曦</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>1500100998</td>\n",
       "      <td>容昆宇</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>1500100999</td>\n",
       "      <td>钟绮晴</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科五班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>1500101000</td>\n",
       "      <td>符瑞渊</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     student_id name  age gender clazz\n",
       "0    1500100001  施笑槐   22      女  文科六班\n",
       "1    1500100002  吕金鹏   24      男  文科六班\n",
       "2    1500100003  单乐蕊   22      女  理科六班\n",
       "3    1500100004  葛德曜   24      男  理科三班\n",
       "4    1500100005  宣谷芹   22      女  理科五班\n",
       "..          ...  ...  ...    ...   ...\n",
       "995  1500100996  厉运凡   24      男  文科三班\n",
       "996  1500100997  陶敬曦   21      男  理科六班\n",
       "997  1500100998  容昆宇   22      男  理科四班\n",
       "998  1500100999  钟绮晴   23      女  文科五班\n",
       "999  1500101000  符瑞渊   23      男  理科六班\n",
       "\n",
       "[1000 rows x 5 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "student.rename(columns={'id':\"student_id\"},inplace=True)\n",
    "student"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ea29797b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>student_id</th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>gender</th>\n",
       "      <th>clazz</th>\n",
       "      <th>id</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1500100001</td>\n",
       "      <td>施笑槐</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>1500100001</td>\n",
       "      <td>406</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1500100002</td>\n",
       "      <td>吕金鹏</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>1500100002</td>\n",
       "      <td>440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1500100003</td>\n",
       "      <td>单乐蕊</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>1500100003</td>\n",
       "      <td>359</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1500100004</td>\n",
       "      <td>葛德曜</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科三班</td>\n",
       "      <td>1500100004</td>\n",
       "      <td>421</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1500100005</td>\n",
       "      <td>宣谷芹</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科五班</td>\n",
       "      <td>1500100005</td>\n",
       "      <td>395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>1500100996</td>\n",
       "      <td>厉运凡</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科三班</td>\n",
       "      <td>1500100996</td>\n",
       "      <td>355</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>1500100997</td>\n",
       "      <td>陶敬曦</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>1500100997</td>\n",
       "      <td>293</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>1500100998</td>\n",
       "      <td>容昆宇</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>1500100998</td>\n",
       "      <td>398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>1500100999</td>\n",
       "      <td>钟绮晴</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科五班</td>\n",
       "      <td>1500100999</td>\n",
       "      <td>371</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>1500101000</td>\n",
       "      <td>符瑞渊</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>1500101000</td>\n",
       "      <td>379</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     student_id name  age gender clazz          id  score\n",
       "0    1500100001  施笑槐   22      女  文科六班  1500100001    406\n",
       "1    1500100002  吕金鹏   24      男  文科六班  1500100002    440\n",
       "2    1500100003  单乐蕊   22      女  理科六班  1500100003    359\n",
       "3    1500100004  葛德曜   24      男  理科三班  1500100004    421\n",
       "4    1500100005  宣谷芹   22      女  理科五班  1500100005    395\n",
       "..          ...  ...  ...    ...   ...         ...    ...\n",
       "995  1500100996  厉运凡   24      男  文科三班  1500100996    355\n",
       "996  1500100997  陶敬曦   21      男  理科六班  1500100997    293\n",
       "997  1500100998  容昆宇   22      男  理科四班  1500100998    398\n",
       "998  1500100999  钟绮晴   23      女  文科五班  1500100999    371\n",
       "999  1500101000  符瑞渊   23      男  理科六班  1500101000    379\n",
       "\n",
       "[1000 rows x 7 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student_merge_res = student.merge(score_total,how='inner',left_on='student_id',right_on='id') \n",
    "student_merge_res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "58a17820",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>student_id</th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>gender</th>\n",
       "      <th>clazz</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1500100001</td>\n",
       "      <td>施笑槐</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>406</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1500100002</td>\n",
       "      <td>吕金鹏</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1500100003</td>\n",
       "      <td>单乐蕊</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>359</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1500100004</td>\n",
       "      <td>葛德曜</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科三班</td>\n",
       "      <td>421</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1500100005</td>\n",
       "      <td>宣谷芹</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科五班</td>\n",
       "      <td>395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>1500100996</td>\n",
       "      <td>厉运凡</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科三班</td>\n",
       "      <td>355</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>1500100997</td>\n",
       "      <td>陶敬曦</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>293</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>1500100998</td>\n",
       "      <td>容昆宇</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>1500100999</td>\n",
       "      <td>钟绮晴</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科五班</td>\n",
       "      <td>371</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>1500101000</td>\n",
       "      <td>符瑞渊</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>379</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     student_id name  age gender clazz  score\n",
       "0    1500100001  施笑槐   22      女  文科六班    406\n",
       "1    1500100002  吕金鹏   24      男  文科六班    440\n",
       "2    1500100003  单乐蕊   22      女  理科六班    359\n",
       "3    1500100004  葛德曜   24      男  理科三班    421\n",
       "4    1500100005  宣谷芹   22      女  理科五班    395\n",
       "..          ...  ...  ...    ...   ...    ...\n",
       "995  1500100996  厉运凡   24      男  文科三班    355\n",
       "996  1500100997  陶敬曦   21      男  理科六班    293\n",
       "997  1500100998  容昆宇   22      男  理科四班    398\n",
       "998  1500100999  钟绮晴   23      女  文科五班    371\n",
       "999  1500101000  符瑞渊   23      男  理科六班    379\n",
       "\n",
       "[1000 rows x 6 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del student_merge_res['id']\n",
    "student_merge_res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "3cd41f2c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>clazz</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>文科一班</td>\n",
       "      <td>628</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>文科三班</td>\n",
       "      <td>568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>文科二班</td>\n",
       "      <td>611</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>文科五班</td>\n",
       "      <td>589</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>文科六班</td>\n",
       "      <td>583</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>文科四班</td>\n",
       "      <td>612</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>理科一班</td>\n",
       "      <td>520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>理科三班</td>\n",
       "      <td>630</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>理科二班</td>\n",
       "      <td>586</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>理科五班</td>\n",
       "      <td>628</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>理科六班</td>\n",
       "      <td>587</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>理科四班</td>\n",
       "      <td>534</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   clazz  score\n",
       "0   文科一班    628\n",
       "1   文科三班    568\n",
       "2   文科二班    611\n",
       "3   文科五班    589\n",
       "4   文科六班    583\n",
       "5   文科四班    612\n",
       "6   理科一班    520\n",
       "7   理科三班    630\n",
       "8   理科二班    586\n",
       "9   理科五班    628\n",
       "10  理科六班    587\n",
       "11  理科四班    534"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 需求4：\n",
    "#   对各班级中总分求第一名\n",
    "student_merge_res.groupby(by=['clazz'])['score'].max().reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "20bc07c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>student_id</th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>gender</th>\n",
       "      <th>clazz</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>634</th>\n",
       "      <td>1500100635</td>\n",
       "      <td>蓬怀绿</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>534</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>589</th>\n",
       "      <td>1500100590</td>\n",
       "      <td>逄中震</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>530</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>938</th>\n",
       "      <td>1500100939</td>\n",
       "      <td>耿智杰</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>530</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>500</th>\n",
       "      <td>1500100501</td>\n",
       "      <td>松迎梅</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>515</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>852</th>\n",
       "      <td>1500100853</td>\n",
       "      <td>林鸿朗</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>515</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>100</th>\n",
       "      <td>1500100101</td>\n",
       "      <td>计又琴</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>227</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>862</th>\n",
       "      <td>1500100863</td>\n",
       "      <td>曹念蕾</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>220</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>708</th>\n",
       "      <td>1500100709</td>\n",
       "      <td>俞昂杰</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>198</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>1500100276</td>\n",
       "      <td>庾运鹏</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>176</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>584</th>\n",
       "      <td>1500100585</td>\n",
       "      <td>穆海超</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>162</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     student_id name  age gender clazz  score\n",
       "634  1500100635  蓬怀绿   23      女  理科四班    534\n",
       "589  1500100590  逄中震   24      男  理科四班    530\n",
       "938  1500100939  耿智杰   23      男  理科四班    530\n",
       "500  1500100501  松迎梅   22      女  理科四班    515\n",
       "852  1500100853  林鸿朗   24      男  理科四班    515\n",
       "..          ...  ...  ...    ...   ...    ...\n",
       "100  1500100101  计又琴   23      女  文科一班    227\n",
       "862  1500100863  曹念蕾   22      女  文科一班    220\n",
       "708  1500100709  俞昂杰   23      男  文科一班    198\n",
       "275  1500100276  庾运鹏   24      男  文科一班    176\n",
       "584  1500100585  穆海超   21      男  文科一班    162\n",
       "\n",
       "[1000 rows x 6 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 需求5\n",
    "#  针对各班级中的总分进行排名\n",
    "\n",
    "student_merge_res.sort_values(by=['clazz','score'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7f32ba4c",
   "metadata": {},
   "outputs": [],
   "source": [
    "#  需求6\n",
    "#    获取各班级中前三名数据\n",
    "#     分析：\n",
    "#          1.根据班级及分数进行排名\n",
    "#          2. 根据排名进行过滤"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "36e04c97",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>student_id</th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>gender</th>\n",
       "      <th>clazz</th>\n",
       "      <th>score</th>\n",
       "      <th>rank</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1500100001</td>\n",
       "      <td>施笑槐</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>406</td>\n",
       "      <td>39.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1500100002</td>\n",
       "      <td>吕金鹏</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>440</td>\n",
       "      <td>24.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1500100003</td>\n",
       "      <td>单乐蕊</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>359</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1500100004</td>\n",
       "      <td>葛德曜</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科三班</td>\n",
       "      <td>421</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1500100005</td>\n",
       "      <td>宣谷芹</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科五班</td>\n",
       "      <td>395</td>\n",
       "      <td>34.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>1500100996</td>\n",
       "      <td>厉运凡</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科三班</td>\n",
       "      <td>355</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>1500100997</td>\n",
       "      <td>陶敬曦</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>293</td>\n",
       "      <td>71.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>1500100998</td>\n",
       "      <td>容昆宇</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>398</td>\n",
       "      <td>36.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>1500100999</td>\n",
       "      <td>钟绮晴</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科五班</td>\n",
       "      <td>371</td>\n",
       "      <td>36.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>1500101000</td>\n",
       "      <td>符瑞渊</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>379</td>\n",
       "      <td>39.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     student_id name  age gender clazz  score  rank\n",
       "0    1500100001  施笑槐   22      女  文科六班    406  39.0\n",
       "1    1500100002  吕金鹏   24      男  文科六班    440  24.0\n",
       "2    1500100003  单乐蕊   22      女  理科六班    359  47.0\n",
       "3    1500100004  葛德曜   24      男  理科三班    421  20.0\n",
       "4    1500100005  宣谷芹   22      女  理科五班    395  34.0\n",
       "..          ...  ...  ...    ...   ...    ...   ...\n",
       "995  1500100996  厉运凡   24      男  文科三班    355  59.0\n",
       "996  1500100997  陶敬曦   21      男  理科六班    293  71.0\n",
       "997  1500100998  容昆宇   22      男  理科四班    398  36.0\n",
       "998  1500100999  钟绮晴   23      女  文科五班    371  36.0\n",
       "999  1500101000  符瑞渊   23      男  理科六班    379  39.0\n",
       "\n",
       "[1000 rows x 7 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# method方法对应参数有多个 可以产考官网案例分析\n",
    "# https://pandas.pydata.org/docs/reference/api/pandas.core.groupby.DataFrameGroupBy.rank.html?highlight=rank#pandas.core.groupby.DataFrameGroupBy.rank\n",
    "# ascending =False 表示倒序\n",
    "student_merge_res['rank'] = student_merge_res.groupby(by=['clazz'])['score'].rank(method='first',ascending=False)\n",
    "student_merge_res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "c37038ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>student_id</th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>gender</th>\n",
       "      <th>clazz</th>\n",
       "      <th>score</th>\n",
       "      <th>rank</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>1500100080</td>\n",
       "      <td>巫景彰</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>理科五班</td>\n",
       "      <td>628</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <td>1500100104</td>\n",
       "      <td>咸冰蝶</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>理科二班</td>\n",
       "      <td>533</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>1500100116</td>\n",
       "      <td>文元蝶</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>文科四班</td>\n",
       "      <td>520</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>1500100136</td>\n",
       "      <td>黎昆鹏</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>583</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159</th>\n",
       "      <td>1500100160</td>\n",
       "      <td>云冰真</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>文科三班</td>\n",
       "      <td>568</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>183</th>\n",
       "      <td>1500100184</td>\n",
       "      <td>夔寻巧</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>理科三班</td>\n",
       "      <td>580</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>234</th>\n",
       "      <td>1500100235</td>\n",
       "      <td>沈香巧</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>理科一班</td>\n",
       "      <td>520</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>257</th>\n",
       "      <td>1500100258</td>\n",
       "      <td>湛昌勋</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>文科四班</td>\n",
       "      <td>604</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>307</th>\n",
       "      <td>1500100308</td>\n",
       "      <td>黄初夏</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>628</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>417</th>\n",
       "      <td>1500100418</td>\n",
       "      <td>蓟海昌</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>文科二班</td>\n",
       "      <td>611</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>433</th>\n",
       "      <td>1500100434</td>\n",
       "      <td>黎雨珍</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科三班</td>\n",
       "      <td>550</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546</th>\n",
       "      <td>1500100547</td>\n",
       "      <td>廖向南</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科五班</td>\n",
       "      <td>584</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>562</th>\n",
       "      <td>1500100563</td>\n",
       "      <td>禄昆鹏</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>536</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571</th>\n",
       "      <td>1500100572</td>\n",
       "      <td>臧忆香</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科三班</td>\n",
       "      <td>550</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>589</th>\n",
       "      <td>1500100590</td>\n",
       "      <td>逄中震</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>530</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>595</th>\n",
       "      <td>1500100596</td>\n",
       "      <td>田晨潍</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>587</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>597</th>\n",
       "      <td>1500100598</td>\n",
       "      <td>宰金鹏</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科三班</td>\n",
       "      <td>551</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>634</th>\n",
       "      <td>1500100635</td>\n",
       "      <td>蓬怀绿</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>534</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>715</th>\n",
       "      <td>1500100716</td>\n",
       "      <td>丰冷霜</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>560</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>761</th>\n",
       "      <td>1500100762</td>\n",
       "      <td>聂德明</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>理科二班</td>\n",
       "      <td>524</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>772</th>\n",
       "      <td>1500100773</td>\n",
       "      <td>傅元蝶</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>理科一班</td>\n",
       "      <td>492</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>822</th>\n",
       "      <td>1500100823</td>\n",
       "      <td>宓新曦</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>文科二班</td>\n",
       "      <td>547</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>833</th>\n",
       "      <td>1500100834</td>\n",
       "      <td>谷念薇</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>理科二班</td>\n",
       "      <td>586</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>838</th>\n",
       "      <td>1500100839</td>\n",
       "      <td>明雁桃</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科五班</td>\n",
       "      <td>557</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>872</th>\n",
       "      <td>1500100873</td>\n",
       "      <td>路鸿志</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科四班</td>\n",
       "      <td>612</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>874</th>\n",
       "      <td>1500100875</td>\n",
       "      <td>马向南</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>595</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>899</th>\n",
       "      <td>1500100900</td>\n",
       "      <td>查思菱</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>562</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>902</th>\n",
       "      <td>1500100903</td>\n",
       "      <td>於依云</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>549</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>903</th>\n",
       "      <td>1500100904</td>\n",
       "      <td>阎元蝶</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科五班</td>\n",
       "      <td>562</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>924</th>\n",
       "      <td>1500100925</td>\n",
       "      <td>卞乐萱</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>理科一班</td>\n",
       "      <td>486</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>928</th>\n",
       "      <td>1500100929</td>\n",
       "      <td>满慕易</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>理科三班</td>\n",
       "      <td>630</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>929</th>\n",
       "      <td>1500100930</td>\n",
       "      <td>闻运凯</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科五班</td>\n",
       "      <td>589</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>938</th>\n",
       "      <td>1500100939</td>\n",
       "      <td>耿智杰</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>530</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>942</th>\n",
       "      <td>1500100943</td>\n",
       "      <td>许昌黎</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>580</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>948</th>\n",
       "      <td>1500100949</td>\n",
       "      <td>颜沛槐</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>文科五班</td>\n",
       "      <td>564</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>953</th>\n",
       "      <td>1500100954</td>\n",
       "      <td>咸芷天</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>文科二班</td>\n",
       "      <td>533</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     student_id name  age gender clazz  score  rank\n",
       "79   1500100080  巫景彰   21      男  理科五班    628   1.0\n",
       "103  1500100104  咸冰蝶   23      女  理科二班    533   2.0\n",
       "115  1500100116  文元蝶   21      女  文科四班    520   3.0\n",
       "135  1500100136  黎昆鹏   22      男  文科六班    583   1.0\n",
       "159  1500100160  云冰真   24      女  文科三班    568   1.0\n",
       "183  1500100184  夔寻巧   24      女  理科三班    580   2.0\n",
       "234  1500100235  沈香巧   24      女  理科一班    520   1.0\n",
       "257  1500100258  湛昌勋   22      男  文科四班    604   2.0\n",
       "307  1500100308  黄初夏   23      女  文科一班    628   1.0\n",
       "417  1500100418  蓟海昌   22      男  文科二班    611   1.0\n",
       "433  1500100434  黎雨珍   23      女  文科三班    550   2.0\n",
       "546  1500100547  廖向南   22      女  理科五班    584   2.0\n",
       "562  1500100563  禄昆鹏   22      男  理科六班    536   3.0\n",
       "571  1500100572  臧忆香   23      女  文科三班    550   3.0\n",
       "589  1500100590  逄中震   24      男  理科四班    530   2.0\n",
       "595  1500100596  田晨潍   21      男  理科六班    587   1.0\n",
       "597  1500100598  宰金鹏   24      男  理科三班    551   3.0\n",
       "634  1500100635  蓬怀绿   23      女  理科四班    534   1.0\n",
       "715  1500100716  丰冷霜   22      女  文科六班    560   3.0\n",
       "761  1500100762  聂德明   23      男  理科二班    524   3.0\n",
       "772  1500100773  傅元蝶   21      女  理科一班    492   2.0\n",
       "822  1500100823  宓新曦   22      男  文科二班    547   2.0\n",
       "833  1500100834  谷念薇   21      女  理科二班    586   1.0\n",
       "838  1500100839  明雁桃   22      女  理科五班    557   3.0\n",
       "872  1500100873  路鸿志   24      男  文科四班    612   1.0\n",
       "874  1500100875  马向南   21      女  文科一班    595   2.0\n",
       "899  1500100900  查思菱   24      女  文科六班    562   2.0\n",
       "902  1500100903  於依云   24      女  理科六班    549   2.0\n",
       "903  1500100904  阎元蝶   23      女  文科五班    562   3.0\n",
       "924  1500100925  卞乐萱   21      女  理科一班    486   3.0\n",
       "928  1500100929  满慕易   21      女  理科三班    630   1.0\n",
       "929  1500100930  闻运凯   24      男  文科五班    589   1.0\n",
       "938  1500100939  耿智杰   23      男  理科四班    530   3.0\n",
       "942  1500100943  许昌黎   21      男  文科一班    580   3.0\n",
       "948  1500100949  颜沛槐   21      女  文科五班    564   2.0\n",
       "953  1500100954  咸芷天   21      女  文科二班    533   3.0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student_merge_res[student_merge_res['rank'] <= 3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "d3494f84",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>student_id</th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>gender</th>\n",
       "      <th>clazz</th>\n",
       "      <th>score</th>\n",
       "      <th>rank</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>1500100080</td>\n",
       "      <td>巫景彰</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>理科五班</td>\n",
       "      <td>628</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <td>1500100104</td>\n",
       "      <td>咸冰蝶</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>理科二班</td>\n",
       "      <td>533</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>1500100116</td>\n",
       "      <td>文元蝶</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>文科四班</td>\n",
       "      <td>520</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>1500100136</td>\n",
       "      <td>黎昆鹏</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>583</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159</th>\n",
       "      <td>1500100160</td>\n",
       "      <td>云冰真</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>文科三班</td>\n",
       "      <td>568</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>183</th>\n",
       "      <td>1500100184</td>\n",
       "      <td>夔寻巧</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>理科三班</td>\n",
       "      <td>580</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>234</th>\n",
       "      <td>1500100235</td>\n",
       "      <td>沈香巧</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>理科一班</td>\n",
       "      <td>520</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>257</th>\n",
       "      <td>1500100258</td>\n",
       "      <td>湛昌勋</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>文科四班</td>\n",
       "      <td>604</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>307</th>\n",
       "      <td>1500100308</td>\n",
       "      <td>黄初夏</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>628</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>417</th>\n",
       "      <td>1500100418</td>\n",
       "      <td>蓟海昌</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>文科二班</td>\n",
       "      <td>611</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>433</th>\n",
       "      <td>1500100434</td>\n",
       "      <td>黎雨珍</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科三班</td>\n",
       "      <td>550</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546</th>\n",
       "      <td>1500100547</td>\n",
       "      <td>廖向南</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科五班</td>\n",
       "      <td>584</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>562</th>\n",
       "      <td>1500100563</td>\n",
       "      <td>禄昆鹏</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>536</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571</th>\n",
       "      <td>1500100572</td>\n",
       "      <td>臧忆香</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科三班</td>\n",
       "      <td>550</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>589</th>\n",
       "      <td>1500100590</td>\n",
       "      <td>逄中震</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>530</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>595</th>\n",
       "      <td>1500100596</td>\n",
       "      <td>田晨潍</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>587</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>597</th>\n",
       "      <td>1500100598</td>\n",
       "      <td>宰金鹏</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科三班</td>\n",
       "      <td>551</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>634</th>\n",
       "      <td>1500100635</td>\n",
       "      <td>蓬怀绿</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>534</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>715</th>\n",
       "      <td>1500100716</td>\n",
       "      <td>丰冷霜</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>560</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>761</th>\n",
       "      <td>1500100762</td>\n",
       "      <td>聂德明</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>理科二班</td>\n",
       "      <td>524</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>772</th>\n",
       "      <td>1500100773</td>\n",
       "      <td>傅元蝶</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>理科一班</td>\n",
       "      <td>492</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>822</th>\n",
       "      <td>1500100823</td>\n",
       "      <td>宓新曦</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>文科二班</td>\n",
       "      <td>547</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>833</th>\n",
       "      <td>1500100834</td>\n",
       "      <td>谷念薇</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>理科二班</td>\n",
       "      <td>586</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>838</th>\n",
       "      <td>1500100839</td>\n",
       "      <td>明雁桃</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科五班</td>\n",
       "      <td>557</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>872</th>\n",
       "      <td>1500100873</td>\n",
       "      <td>路鸿志</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科四班</td>\n",
       "      <td>612</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>874</th>\n",
       "      <td>1500100875</td>\n",
       "      <td>马向南</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>595</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>899</th>\n",
       "      <td>1500100900</td>\n",
       "      <td>查思菱</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>562</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>902</th>\n",
       "      <td>1500100903</td>\n",
       "      <td>於依云</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>549</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>903</th>\n",
       "      <td>1500100904</td>\n",
       "      <td>阎元蝶</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科五班</td>\n",
       "      <td>562</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>924</th>\n",
       "      <td>1500100925</td>\n",
       "      <td>卞乐萱</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>理科一班</td>\n",
       "      <td>486</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>928</th>\n",
       "      <td>1500100929</td>\n",
       "      <td>满慕易</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>理科三班</td>\n",
       "      <td>630</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>929</th>\n",
       "      <td>1500100930</td>\n",
       "      <td>闻运凯</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科五班</td>\n",
       "      <td>589</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>938</th>\n",
       "      <td>1500100939</td>\n",
       "      <td>耿智杰</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>530</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>942</th>\n",
       "      <td>1500100943</td>\n",
       "      <td>许昌黎</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>580</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>948</th>\n",
       "      <td>1500100949</td>\n",
       "      <td>颜沛槐</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>文科五班</td>\n",
       "      <td>564</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>953</th>\n",
       "      <td>1500100954</td>\n",
       "      <td>咸芷天</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>文科二班</td>\n",
       "      <td>533</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     student_id name  age gender clazz  score  rank\n",
       "79   1500100080  巫景彰   21      男  理科五班    628   1.0\n",
       "103  1500100104  咸冰蝶   23      女  理科二班    533   2.0\n",
       "115  1500100116  文元蝶   21      女  文科四班    520   3.0\n",
       "135  1500100136  黎昆鹏   22      男  文科六班    583   1.0\n",
       "159  1500100160  云冰真   24      女  文科三班    568   1.0\n",
       "183  1500100184  夔寻巧   24      女  理科三班    580   2.0\n",
       "234  1500100235  沈香巧   24      女  理科一班    520   1.0\n",
       "257  1500100258  湛昌勋   22      男  文科四班    604   2.0\n",
       "307  1500100308  黄初夏   23      女  文科一班    628   1.0\n",
       "417  1500100418  蓟海昌   22      男  文科二班    611   1.0\n",
       "433  1500100434  黎雨珍   23      女  文科三班    550   2.0\n",
       "546  1500100547  廖向南   22      女  理科五班    584   2.0\n",
       "562  1500100563  禄昆鹏   22      男  理科六班    536   3.0\n",
       "571  1500100572  臧忆香   23      女  文科三班    550   3.0\n",
       "589  1500100590  逄中震   24      男  理科四班    530   2.0\n",
       "595  1500100596  田晨潍   21      男  理科六班    587   1.0\n",
       "597  1500100598  宰金鹏   24      男  理科三班    551   3.0\n",
       "634  1500100635  蓬怀绿   23      女  理科四班    534   1.0\n",
       "715  1500100716  丰冷霜   22      女  文科六班    560   3.0\n",
       "761  1500100762  聂德明   23      男  理科二班    524   3.0\n",
       "772  1500100773  傅元蝶   21      女  理科一班    492   2.0\n",
       "822  1500100823  宓新曦   22      男  文科二班    547   2.0\n",
       "833  1500100834  谷念薇   21      女  理科二班    586   1.0\n",
       "838  1500100839  明雁桃   22      女  理科五班    557   3.0\n",
       "872  1500100873  路鸿志   24      男  文科四班    612   1.0\n",
       "874  1500100875  马向南   21      女  文科一班    595   2.0\n",
       "899  1500100900  查思菱   24      女  文科六班    562   2.0\n",
       "902  1500100903  於依云   24      女  理科六班    549   2.0\n",
       "903  1500100904  阎元蝶   23      女  文科五班    562   3.0\n",
       "924  1500100925  卞乐萱   21      女  理科一班    486   3.0\n",
       "928  1500100929  满慕易   21      女  理科三班    630   1.0\n",
       "929  1500100930  闻运凯   24      男  文科五班    589   1.0\n",
       "938  1500100939  耿智杰   23      男  理科四班    530   3.0\n",
       "942  1500100943  许昌黎   21      男  文科一班    580   3.0\n",
       "948  1500100949  颜沛槐   21      女  文科五班    564   2.0\n",
       "953  1500100954  咸芷天   21      女  文科二班    533   3.0"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按行取值方式二\n",
    "student_merge_res.loc[student_merge_res['rank'] <= 3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "675c98a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>student_id</th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>gender</th>\n",
       "      <th>clazz</th>\n",
       "      <th>score</th>\n",
       "      <th>rank</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>1500100080</td>\n",
       "      <td>巫景彰</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>理科五班</td>\n",
       "      <td>628</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <td>1500100104</td>\n",
       "      <td>咸冰蝶</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>理科二班</td>\n",
       "      <td>533</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>1500100116</td>\n",
       "      <td>文元蝶</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>文科四班</td>\n",
       "      <td>520</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>1500100136</td>\n",
       "      <td>黎昆鹏</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>583</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159</th>\n",
       "      <td>1500100160</td>\n",
       "      <td>云冰真</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>文科三班</td>\n",
       "      <td>568</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>183</th>\n",
       "      <td>1500100184</td>\n",
       "      <td>夔寻巧</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>理科三班</td>\n",
       "      <td>580</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>234</th>\n",
       "      <td>1500100235</td>\n",
       "      <td>沈香巧</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>理科一班</td>\n",
       "      <td>520</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>257</th>\n",
       "      <td>1500100258</td>\n",
       "      <td>湛昌勋</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>文科四班</td>\n",
       "      <td>604</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>307</th>\n",
       "      <td>1500100308</td>\n",
       "      <td>黄初夏</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>628</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>417</th>\n",
       "      <td>1500100418</td>\n",
       "      <td>蓟海昌</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>文科二班</td>\n",
       "      <td>611</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>433</th>\n",
       "      <td>1500100434</td>\n",
       "      <td>黎雨珍</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科三班</td>\n",
       "      <td>550</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546</th>\n",
       "      <td>1500100547</td>\n",
       "      <td>廖向南</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科五班</td>\n",
       "      <td>584</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>562</th>\n",
       "      <td>1500100563</td>\n",
       "      <td>禄昆鹏</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>536</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571</th>\n",
       "      <td>1500100572</td>\n",
       "      <td>臧忆香</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科三班</td>\n",
       "      <td>550</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>589</th>\n",
       "      <td>1500100590</td>\n",
       "      <td>逄中震</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>530</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>595</th>\n",
       "      <td>1500100596</td>\n",
       "      <td>田晨潍</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>587</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>597</th>\n",
       "      <td>1500100598</td>\n",
       "      <td>宰金鹏</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>理科三班</td>\n",
       "      <td>551</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>634</th>\n",
       "      <td>1500100635</td>\n",
       "      <td>蓬怀绿</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>534</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>715</th>\n",
       "      <td>1500100716</td>\n",
       "      <td>丰冷霜</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>560</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>761</th>\n",
       "      <td>1500100762</td>\n",
       "      <td>聂德明</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>理科二班</td>\n",
       "      <td>524</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>772</th>\n",
       "      <td>1500100773</td>\n",
       "      <td>傅元蝶</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>理科一班</td>\n",
       "      <td>492</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>822</th>\n",
       "      <td>1500100823</td>\n",
       "      <td>宓新曦</td>\n",
       "      <td>22</td>\n",
       "      <td>男</td>\n",
       "      <td>文科二班</td>\n",
       "      <td>547</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>833</th>\n",
       "      <td>1500100834</td>\n",
       "      <td>谷念薇</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>理科二班</td>\n",
       "      <td>586</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>838</th>\n",
       "      <td>1500100839</td>\n",
       "      <td>明雁桃</td>\n",
       "      <td>22</td>\n",
       "      <td>女</td>\n",
       "      <td>理科五班</td>\n",
       "      <td>557</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>872</th>\n",
       "      <td>1500100873</td>\n",
       "      <td>路鸿志</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科四班</td>\n",
       "      <td>612</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>874</th>\n",
       "      <td>1500100875</td>\n",
       "      <td>马向南</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>595</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>899</th>\n",
       "      <td>1500100900</td>\n",
       "      <td>查思菱</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>文科六班</td>\n",
       "      <td>562</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>902</th>\n",
       "      <td>1500100903</td>\n",
       "      <td>於依云</td>\n",
       "      <td>24</td>\n",
       "      <td>女</td>\n",
       "      <td>理科六班</td>\n",
       "      <td>549</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>903</th>\n",
       "      <td>1500100904</td>\n",
       "      <td>阎元蝶</td>\n",
       "      <td>23</td>\n",
       "      <td>女</td>\n",
       "      <td>文科五班</td>\n",
       "      <td>562</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>924</th>\n",
       "      <td>1500100925</td>\n",
       "      <td>卞乐萱</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>理科一班</td>\n",
       "      <td>486</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>928</th>\n",
       "      <td>1500100929</td>\n",
       "      <td>满慕易</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>理科三班</td>\n",
       "      <td>630</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>929</th>\n",
       "      <td>1500100930</td>\n",
       "      <td>闻运凯</td>\n",
       "      <td>24</td>\n",
       "      <td>男</td>\n",
       "      <td>文科五班</td>\n",
       "      <td>589</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>938</th>\n",
       "      <td>1500100939</td>\n",
       "      <td>耿智杰</td>\n",
       "      <td>23</td>\n",
       "      <td>男</td>\n",
       "      <td>理科四班</td>\n",
       "      <td>530</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>942</th>\n",
       "      <td>1500100943</td>\n",
       "      <td>许昌黎</td>\n",
       "      <td>21</td>\n",
       "      <td>男</td>\n",
       "      <td>文科一班</td>\n",
       "      <td>580</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>948</th>\n",
       "      <td>1500100949</td>\n",
       "      <td>颜沛槐</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>文科五班</td>\n",
       "      <td>564</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>953</th>\n",
       "      <td>1500100954</td>\n",
       "      <td>咸芷天</td>\n",
       "      <td>21</td>\n",
       "      <td>女</td>\n",
       "      <td>文科二班</td>\n",
       "      <td>533</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     student_id name  age gender clazz  score  rank\n",
       "79   1500100080  巫景彰   21      男  理科五班    628   1.0\n",
       "103  1500100104  咸冰蝶   23      女  理科二班    533   2.0\n",
       "115  1500100116  文元蝶   21      女  文科四班    520   3.0\n",
       "135  1500100136  黎昆鹏   22      男  文科六班    583   1.0\n",
       "159  1500100160  云冰真   24      女  文科三班    568   1.0\n",
       "183  1500100184  夔寻巧   24      女  理科三班    580   2.0\n",
       "234  1500100235  沈香巧   24      女  理科一班    520   1.0\n",
       "257  1500100258  湛昌勋   22      男  文科四班    604   2.0\n",
       "307  1500100308  黄初夏   23      女  文科一班    628   1.0\n",
       "417  1500100418  蓟海昌   22      男  文科二班    611   1.0\n",
       "433  1500100434  黎雨珍   23      女  文科三班    550   2.0\n",
       "546  1500100547  廖向南   22      女  理科五班    584   2.0\n",
       "562  1500100563  禄昆鹏   22      男  理科六班    536   3.0\n",
       "571  1500100572  臧忆香   23      女  文科三班    550   3.0\n",
       "589  1500100590  逄中震   24      男  理科四班    530   2.0\n",
       "595  1500100596  田晨潍   21      男  理科六班    587   1.0\n",
       "597  1500100598  宰金鹏   24      男  理科三班    551   3.0\n",
       "634  1500100635  蓬怀绿   23      女  理科四班    534   1.0\n",
       "715  1500100716  丰冷霜   22      女  文科六班    560   3.0\n",
       "761  1500100762  聂德明   23      男  理科二班    524   3.0\n",
       "772  1500100773  傅元蝶   21      女  理科一班    492   2.0\n",
       "822  1500100823  宓新曦   22      男  文科二班    547   2.0\n",
       "833  1500100834  谷念薇   21      女  理科二班    586   1.0\n",
       "838  1500100839  明雁桃   22      女  理科五班    557   3.0\n",
       "872  1500100873  路鸿志   24      男  文科四班    612   1.0\n",
       "874  1500100875  马向南   21      女  文科一班    595   2.0\n",
       "899  1500100900  查思菱   24      女  文科六班    562   2.0\n",
       "902  1500100903  於依云   24      女  理科六班    549   2.0\n",
       "903  1500100904  阎元蝶   23      女  文科五班    562   3.0\n",
       "924  1500100925  卞乐萱   21      女  理科一班    486   3.0\n",
       "928  1500100929  满慕易   21      女  理科三班    630   1.0\n",
       "929  1500100930  闻运凯   24      男  文科五班    589   1.0\n",
       "938  1500100939  耿智杰   23      男  理科四班    530   3.0\n",
       "942  1500100943  许昌黎   21      男  文科一班    580   3.0\n",
       "948  1500100949  颜沛槐   21      女  文科五班    564   2.0\n",
       "953  1500100954  咸芷天   21      女  文科二班    533   3.0"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 排序并写出至CSV文件\n",
    "student_score_top3 =  student_merge_res.loc[student_merge_res['rank'] <= 3]\n",
    "student_score_top3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "d75f58a3",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\app\\python379\\lib\\site-packages\\pandas\\util\\_decorators.py:311: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  return func(*args, **kwargs)\n"
     ]
    }
   ],
   "source": [
    "student_score_top3.sort_values(by=['clazz','rank'],inplace=True)\n",
    "# 当给的文件路径报错时，可以加r对字符串进行取消转义\n",
    "student_score_top3.to_csv(r\"../data/student_score_top3.csv\",header=False,index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ba5708a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "3f4824c4",
   "metadata": {},
   "source": [
    "# 缺失值处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "9c81e4d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>班名次</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>杨璐</td>\n",
       "      <td>131.0</td>\n",
       "      <td>143.0</td>\n",
       "      <td>144.0</td>\n",
       "      <td>418.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>王雪</td>\n",
       "      <td>131.0</td>\n",
       "      <td>135.0</td>\n",
       "      <td>144.0</td>\n",
       "      <td>410.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩林霖</td>\n",
       "      <td>127.0</td>\n",
       "      <td>139.0</td>\n",
       "      <td>142.0</td>\n",
       "      <td>408.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沙龙逸</td>\n",
       "      <td>NaN</td>\n",
       "      <td>148.0</td>\n",
       "      <td>136.0</td>\n",
       "      <td>407.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>401.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>赵森</td>\n",
       "      <td>90.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>183.0</td>\n",
       "      <td>64.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>满朝升</td>\n",
       "      <td>78.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>47.0</td>\n",
       "      <td>170.0</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>李忠浩</td>\n",
       "      <td>86.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>46.0</td>\n",
       "      <td>164.0</td>\n",
       "      <td>66.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>侯禹志</td>\n",
       "      <td>75.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>132.0</td>\n",
       "      <td>67.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>尹鸿涛</td>\n",
       "      <td>66.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>123.0</td>\n",
       "      <td>68.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名     语文     数学     英语     总分   班名次\n",
       "0    杨璐  131.0  143.0  144.0  418.0   1.0\n",
       "1    王雪  131.0  135.0  144.0  410.0   2.0\n",
       "2   韩林霖  127.0  139.0  142.0  408.0   3.0\n",
       "3   沙龙逸    NaN  148.0  136.0  407.0   4.0\n",
       "4   李鉴学    NaN  135.0  140.0  401.0   5.0\n",
       "..  ...    ...    ...    ...    ...   ...\n",
       "63   赵森   90.0   29.0   64.0  183.0  64.0\n",
       "64  满朝升   78.0   45.0   47.0  170.0  65.0\n",
       "65  李忠浩   86.0   32.0   46.0  164.0  66.0\n",
       "66  侯禹志   75.0   23.0   34.0  132.0  67.0\n",
       "67  尹鸿涛   66.0   23.0   34.0  123.0  68.0\n",
       "\n",
       "[68 rows x 6 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "grade_empty = pd.read_csv('../data/student_grade_empty.txt',encoding='utf8',sep='\\t')\n",
    "grade_empty"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "637958eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# NULL 值处理方式\n",
    "#    1. 删除\n",
    "#    2. null值填充\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "2c1e8ee2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>班名次</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沙龙逸</td>\n",
       "      <td>NaN</td>\n",
       "      <td>148.0</td>\n",
       "      <td>136.0</td>\n",
       "      <td>407.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>401.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>林世博</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>387.0</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>张希</td>\n",
       "      <td>NaN</td>\n",
       "      <td>130.0</td>\n",
       "      <td>134.0</td>\n",
       "      <td>387.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>徐冲</td>\n",
       "      <td>NaN</td>\n",
       "      <td>124.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>苑宇飞</td>\n",
       "      <td>NaN</td>\n",
       "      <td>136.0</td>\n",
       "      <td>131.0</td>\n",
       "      <td>385.0</td>\n",
       "      <td>13.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>赵殿宇</td>\n",
       "      <td>NaN</td>\n",
       "      <td>109.0</td>\n",
       "      <td>130.0</td>\n",
       "      <td>351.0</td>\n",
       "      <td>27.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>张智文</td>\n",
       "      <td>NaN</td>\n",
       "      <td>116.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>350.0</td>\n",
       "      <td>28.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>何旭</td>\n",
       "      <td>NaN</td>\n",
       "      <td>113.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>347.0</td>\n",
       "      <td>31.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名  语文     数学     英语     总分   班名次\n",
       "3   沙龙逸 NaN  148.0  136.0  407.0   4.0\n",
       "4   李鉴学 NaN  135.0  140.0  401.0   5.0\n",
       "9   林世博 NaN    NaN    NaN  387.0  10.0\n",
       "10   张希 NaN  130.0  134.0  387.0  11.0\n",
       "11   徐冲 NaN  124.0    NaN    NaN   NaN\n",
       "12  苑宇飞 NaN  136.0  131.0  385.0  13.0\n",
       "26  赵殿宇 NaN  109.0  130.0  351.0  27.0\n",
       "27  张智文 NaN  116.0  125.0  350.0  28.0\n",
       "30   何旭 NaN  113.0  120.0  347.0  31.0"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看NULL值\n",
    "grade_empty[  grade_empty['语文'].isnull()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "44e8d55f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>班名次</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沙龙逸</td>\n",
       "      <td>NaN</td>\n",
       "      <td>148.0</td>\n",
       "      <td>136.0</td>\n",
       "      <td>407.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>401.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>林世博</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>387.0</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>张希</td>\n",
       "      <td>NaN</td>\n",
       "      <td>130.0</td>\n",
       "      <td>134.0</td>\n",
       "      <td>387.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>徐冲</td>\n",
       "      <td>NaN</td>\n",
       "      <td>124.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>苑宇飞</td>\n",
       "      <td>NaN</td>\n",
       "      <td>136.0</td>\n",
       "      <td>131.0</td>\n",
       "      <td>385.0</td>\n",
       "      <td>13.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>赵殿宇</td>\n",
       "      <td>NaN</td>\n",
       "      <td>109.0</td>\n",
       "      <td>130.0</td>\n",
       "      <td>351.0</td>\n",
       "      <td>27.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>张智文</td>\n",
       "      <td>NaN</td>\n",
       "      <td>116.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>350.0</td>\n",
       "      <td>28.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>何旭</td>\n",
       "      <td>NaN</td>\n",
       "      <td>113.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>347.0</td>\n",
       "      <td>31.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>林世博</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>387.0</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>张俊奎</td>\n",
       "      <td>103.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>317.0</td>\n",
       "      <td>42.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>林世博</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>387.0</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>徐冲</td>\n",
       "      <td>NaN</td>\n",
       "      <td>124.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>范作鑫</td>\n",
       "      <td>121.0</td>\n",
       "      <td>127.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>16.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>赵永刚</td>\n",
       "      <td>116.0</td>\n",
       "      <td>131.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>369.0</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>张俊奎</td>\n",
       "      <td>103.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>317.0</td>\n",
       "      <td>42.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名     语文     数学     英语     总分   班名次\n",
       "3   沙龙逸    NaN  148.0  136.0  407.0   4.0\n",
       "4   李鉴学    NaN  135.0  140.0  401.0   5.0\n",
       "9   林世博    NaN    NaN    NaN  387.0  10.0\n",
       "10   张希    NaN  130.0  134.0  387.0  11.0\n",
       "11   徐冲    NaN  124.0    NaN    NaN   NaN\n",
       "12  苑宇飞    NaN  136.0  131.0  385.0  13.0\n",
       "26  赵殿宇    NaN  109.0  130.0  351.0  27.0\n",
       "27  张智文    NaN  116.0  125.0  350.0  28.0\n",
       "30   何旭    NaN  113.0  120.0  347.0  31.0\n",
       "9   林世博    NaN    NaN    NaN  387.0  10.0\n",
       "41  张俊奎  103.0    NaN    NaN  317.0  42.0\n",
       "9   林世博    NaN    NaN    NaN  387.0  10.0\n",
       "11   徐冲    NaN  124.0    NaN    NaN   NaN\n",
       "15  范作鑫  121.0  127.0    NaN    NaN  16.0\n",
       "21  赵永刚  116.0  131.0    NaN  369.0  22.0\n",
       "41  张俊奎  103.0    NaN    NaN  317.0  42.0"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 不推荐  有重复值\n",
    "grade_empty[  grade_empty['语文'].isnull() ].append(grade_empty[  grade_empty['数学'].isnull() ]).append(grade_empty[  grade_empty['英语'].isnull() ])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "e8d21c43",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>班名次</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沙龙逸</td>\n",
       "      <td>NaN</td>\n",
       "      <td>148.0</td>\n",
       "      <td>136.0</td>\n",
       "      <td>407.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>401.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>林世博</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>387.0</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>张希</td>\n",
       "      <td>NaN</td>\n",
       "      <td>130.0</td>\n",
       "      <td>134.0</td>\n",
       "      <td>387.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>徐冲</td>\n",
       "      <td>NaN</td>\n",
       "      <td>124.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>苑宇飞</td>\n",
       "      <td>NaN</td>\n",
       "      <td>136.0</td>\n",
       "      <td>131.0</td>\n",
       "      <td>385.0</td>\n",
       "      <td>13.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>范作鑫</td>\n",
       "      <td>121.0</td>\n",
       "      <td>127.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>16.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>赵永刚</td>\n",
       "      <td>116.0</td>\n",
       "      <td>131.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>369.0</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>赵殿宇</td>\n",
       "      <td>NaN</td>\n",
       "      <td>109.0</td>\n",
       "      <td>130.0</td>\n",
       "      <td>351.0</td>\n",
       "      <td>27.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>张智文</td>\n",
       "      <td>NaN</td>\n",
       "      <td>116.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>350.0</td>\n",
       "      <td>28.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>何旭</td>\n",
       "      <td>NaN</td>\n",
       "      <td>113.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>347.0</td>\n",
       "      <td>31.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>张俊奎</td>\n",
       "      <td>103.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>317.0</td>\n",
       "      <td>42.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名     语文     数学     英语     总分   班名次\n",
       "3   沙龙逸    NaN  148.0  136.0  407.0   4.0\n",
       "4   李鉴学    NaN  135.0  140.0  401.0   5.0\n",
       "9   林世博    NaN    NaN    NaN  387.0  10.0\n",
       "10   张希    NaN  130.0  134.0  387.0  11.0\n",
       "11   徐冲    NaN  124.0    NaN    NaN   NaN\n",
       "12  苑宇飞    NaN  136.0  131.0  385.0  13.0\n",
       "15  范作鑫  121.0  127.0    NaN    NaN  16.0\n",
       "21  赵永刚  116.0  131.0    NaN  369.0  22.0\n",
       "26  赵殿宇    NaN  109.0  130.0  351.0  27.0\n",
       "27  张智文    NaN  116.0  125.0  350.0  28.0\n",
       "30   何旭    NaN  113.0  120.0  347.0  31.0\n",
       "41  张俊奎  103.0    NaN    NaN  317.0  42.0"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "grade_empty[grade_empty['语文'].isnull() | grade_empty['英语'].isnull() | grade_empty['数学'].isnull()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "2cce0dbd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 51 entries, 0 to 67\n",
      "Data columns (total 6 columns):\n",
      " #   Column  Non-Null Count  Dtype  \n",
      "---  ------  --------------  -----  \n",
      " 0   姓名      51 non-null     object \n",
      " 1   语文      51 non-null     float64\n",
      " 2   数学      51 non-null     float64\n",
      " 3   英语      51 non-null     float64\n",
      " 4   总分      51 non-null     float64\n",
      " 5   班名次     51 non-null     float64\n",
      "dtypes: float64(5), object(1)\n",
      "memory usage: 2.8+ KB\n"
     ]
    }
   ],
   "source": [
    "# 删除NULL值\n",
    "# 不加参数 删除所有为null \n",
    "grade_empty.dropna().info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "4ce48d91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>班名次</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>杨璐</td>\n",
       "      <td>131.0</td>\n",
       "      <td>143.0</td>\n",
       "      <td>144.0</td>\n",
       "      <td>418.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>王雪</td>\n",
       "      <td>131.0</td>\n",
       "      <td>135.0</td>\n",
       "      <td>144.0</td>\n",
       "      <td>410.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩林霖</td>\n",
       "      <td>127.0</td>\n",
       "      <td>139.0</td>\n",
       "      <td>142.0</td>\n",
       "      <td>408.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>韩雨萌</td>\n",
       "      <td>129.0</td>\n",
       "      <td>133.0</td>\n",
       "      <td>138.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>刘帅</td>\n",
       "      <td>116.0</td>\n",
       "      <td>143.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>399.0</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>康惠雯</td>\n",
       "      <td>114.0</td>\n",
       "      <td>142.0</td>\n",
       "      <td>139.0</td>\n",
       "      <td>395.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>刘钰婷</td>\n",
       "      <td>115.0</td>\n",
       "      <td>139.0</td>\n",
       "      <td>135.0</td>\n",
       "      <td>389.0</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>卢一凡</td>\n",
       "      <td>121.0</td>\n",
       "      <td>123.0</td>\n",
       "      <td>139.0</td>\n",
       "      <td>383.0</td>\n",
       "      <td>14.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>张瑞鑫</td>\n",
       "      <td>126.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>139.0</td>\n",
       "      <td>380.0</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>裴子翔</td>\n",
       "      <td>111.0</td>\n",
       "      <td>139.0</td>\n",
       "      <td>128.0</td>\n",
       "      <td>378.0</td>\n",
       "      <td>17.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>武传禹</td>\n",
       "      <td>119.0</td>\n",
       "      <td>129.0</td>\n",
       "      <td>130.0</td>\n",
       "      <td>378.0</td>\n",
       "      <td>18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>任雪桐</td>\n",
       "      <td>124.0</td>\n",
       "      <td>108.0</td>\n",
       "      <td>144.0</td>\n",
       "      <td>376.0</td>\n",
       "      <td>19.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>刘姗</td>\n",
       "      <td>124.0</td>\n",
       "      <td>128.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>374.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>王柏坤</td>\n",
       "      <td>121.0</td>\n",
       "      <td>123.0</td>\n",
       "      <td>128.0</td>\n",
       "      <td>372.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>张馨月大</td>\n",
       "      <td>114.0</td>\n",
       "      <td>124.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>张曦月</td>\n",
       "      <td>116.0</td>\n",
       "      <td>123.0</td>\n",
       "      <td>119.0</td>\n",
       "      <td>358.0</td>\n",
       "      <td>24.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>胡丁文</td>\n",
       "      <td>116.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>118.0</td>\n",
       "      <td>356.0</td>\n",
       "      <td>25.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>赵美欣</td>\n",
       "      <td>118.0</td>\n",
       "      <td>126.0</td>\n",
       "      <td>111.0</td>\n",
       "      <td>355.0</td>\n",
       "      <td>26.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>李季</td>\n",
       "      <td>114.0</td>\n",
       "      <td>117.0</td>\n",
       "      <td>118.0</td>\n",
       "      <td>349.0</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>杨加晖</td>\n",
       "      <td>110.0</td>\n",
       "      <td>102.0</td>\n",
       "      <td>136.0</td>\n",
       "      <td>348.0</td>\n",
       "      <td>30.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>张智凯</td>\n",
       "      <td>110.0</td>\n",
       "      <td>117.0</td>\n",
       "      <td>119.0</td>\n",
       "      <td>346.0</td>\n",
       "      <td>32.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>张晓爽</td>\n",
       "      <td>113.0</td>\n",
       "      <td>113.0</td>\n",
       "      <td>119.0</td>\n",
       "      <td>345.0</td>\n",
       "      <td>33.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>NaN</td>\n",
       "      <td>117.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>106.0</td>\n",
       "      <td>344.0</td>\n",
       "      <td>34.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>NaN</td>\n",
       "      <td>112.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>126.0</td>\n",
       "      <td>343.0</td>\n",
       "      <td>35.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>贺俊文</td>\n",
       "      <td>103.0</td>\n",
       "      <td>127.0</td>\n",
       "      <td>110.0</td>\n",
       "      <td>340.0</td>\n",
       "      <td>36.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>张馨月小</td>\n",
       "      <td>108.0</td>\n",
       "      <td>110.0</td>\n",
       "      <td>119.0</td>\n",
       "      <td>337.0</td>\n",
       "      <td>37.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>代诗涵</td>\n",
       "      <td>105.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>126.0</td>\n",
       "      <td>336.0</td>\n",
       "      <td>38.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>艾宇</td>\n",
       "      <td>115.0</td>\n",
       "      <td>111.0</td>\n",
       "      <td>106.0</td>\n",
       "      <td>332.0</td>\n",
       "      <td>39.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>黄俊焯</td>\n",
       "      <td>101.0</td>\n",
       "      <td>112.0</td>\n",
       "      <td>106.0</td>\n",
       "      <td>319.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>邹建志</td>\n",
       "      <td>98.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>116.0</td>\n",
       "      <td>318.0</td>\n",
       "      <td>41.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>孙波</td>\n",
       "      <td>96.0</td>\n",
       "      <td>130.0</td>\n",
       "      <td>89.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>43.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>张良</td>\n",
       "      <td>105.0</td>\n",
       "      <td>102.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>44.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>王春月</td>\n",
       "      <td>118.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>112.0</td>\n",
       "      <td>312.0</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>代明哲</td>\n",
       "      <td>101.0</td>\n",
       "      <td>91.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>307.0</td>\n",
       "      <td>46.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>张开羽</td>\n",
       "      <td>112.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>306.0</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>狄建译</td>\n",
       "      <td>109.0</td>\n",
       "      <td>68.0</td>\n",
       "      <td>126.0</td>\n",
       "      <td>303.0</td>\n",
       "      <td>48.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>张家硕</td>\n",
       "      <td>107.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>129.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>49.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>郭娜</td>\n",
       "      <td>94.0</td>\n",
       "      <td>98.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>296.0</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>周坤</td>\n",
       "      <td>107.0</td>\n",
       "      <td>76.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>287.0</td>\n",
       "      <td>51.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>洪禹</td>\n",
       "      <td>106.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>286.0</td>\n",
       "      <td>52.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>王治超</td>\n",
       "      <td>105.0</td>\n",
       "      <td>95.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>282.0</td>\n",
       "      <td>53.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>臧云飞</td>\n",
       "      <td>101.0</td>\n",
       "      <td>59.0</td>\n",
       "      <td>108.0</td>\n",
       "      <td>268.0</td>\n",
       "      <td>54.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>袁茂哲</td>\n",
       "      <td>85.0</td>\n",
       "      <td>95.0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>265.0</td>\n",
       "      <td>55.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>丁婉艺</td>\n",
       "      <td>95.0</td>\n",
       "      <td>71.0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>251.0</td>\n",
       "      <td>56.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>于娇莹</td>\n",
       "      <td>97.0</td>\n",
       "      <td>76.0</td>\n",
       "      <td>71.0</td>\n",
       "      <td>244.0</td>\n",
       "      <td>57.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>刘旭辉</td>\n",
       "      <td>99.0</td>\n",
       "      <td>87.0</td>\n",
       "      <td>44.0</td>\n",
       "      <td>230.0</td>\n",
       "      <td>58.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>张宇婷</td>\n",
       "      <td>83.0</td>\n",
       "      <td>61.0</td>\n",
       "      <td>71.0</td>\n",
       "      <td>215.0</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>黄明涛</td>\n",
       "      <td>87.0</td>\n",
       "      <td>77.0</td>\n",
       "      <td>43.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>吕文卓</td>\n",
       "      <td>82.0</td>\n",
       "      <td>53.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>197.0</td>\n",
       "      <td>61.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>王晟煜</td>\n",
       "      <td>79.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>192.0</td>\n",
       "      <td>62.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>孙龙基</td>\n",
       "      <td>99.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>187.0</td>\n",
       "      <td>63.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>赵森</td>\n",
       "      <td>90.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>183.0</td>\n",
       "      <td>64.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>满朝升</td>\n",
       "      <td>78.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>47.0</td>\n",
       "      <td>170.0</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>李忠浩</td>\n",
       "      <td>86.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>46.0</td>\n",
       "      <td>164.0</td>\n",
       "      <td>66.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>侯禹志</td>\n",
       "      <td>75.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>132.0</td>\n",
       "      <td>67.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>尹鸿涛</td>\n",
       "      <td>66.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>123.0</td>\n",
       "      <td>68.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      姓名     语文     数学     英语     总分   班名次\n",
       "0     杨璐  131.0  143.0  144.0  418.0   1.0\n",
       "1     王雪  131.0  135.0  144.0  410.0   2.0\n",
       "2    韩林霖  127.0  139.0  142.0  408.0   3.0\n",
       "5    韩雨萌  129.0  133.0  138.0  400.0   6.0\n",
       "6     刘帅  116.0  143.0  140.0  399.0   7.0\n",
       "7    康惠雯  114.0  142.0  139.0  395.0   8.0\n",
       "8    刘钰婷  115.0  139.0  135.0  389.0   9.0\n",
       "13   卢一凡  121.0  123.0  139.0  383.0  14.0\n",
       "14   张瑞鑫  126.0  115.0  139.0  380.0  15.0\n",
       "16   裴子翔  111.0  139.0  128.0  378.0  17.0\n",
       "17   武传禹  119.0  129.0  130.0  378.0  18.0\n",
       "18   任雪桐  124.0  108.0  144.0  376.0  19.0\n",
       "19    刘姗  124.0  128.0  122.0  374.0  20.0\n",
       "20   王柏坤  121.0  123.0  128.0  372.0  21.0\n",
       "22  张馨月大  114.0  124.0  122.0  360.0  23.0\n",
       "23   张曦月  116.0  123.0  119.0  358.0  24.0\n",
       "24   胡丁文  116.0  122.0  118.0  356.0  25.0\n",
       "25   赵美欣  118.0  126.0  111.0  355.0  26.0\n",
       "28    李季  114.0  117.0  118.0  349.0  29.0\n",
       "29   杨加晖  110.0  102.0  136.0  348.0  30.0\n",
       "31   张智凯  110.0  117.0  119.0  346.0  32.0\n",
       "32   张晓爽  113.0  113.0  119.0  345.0  33.0\n",
       "33   NaN  117.0  121.0  106.0  344.0  34.0\n",
       "34   NaN  112.0  105.0  126.0  343.0  35.0\n",
       "35   贺俊文  103.0  127.0  110.0  340.0  36.0\n",
       "36  张馨月小  108.0  110.0  119.0  337.0  37.0\n",
       "37   代诗涵  105.0  105.0  126.0  336.0  38.0\n",
       "38    艾宇  115.0  111.0  106.0  332.0  39.0\n",
       "39   黄俊焯  101.0  112.0  106.0  319.0  40.0\n",
       "40   邹建志   98.0  104.0  116.0  318.0  41.0\n",
       "42    孙波   96.0  130.0   89.0    NaN  43.0\n",
       "43    张良  105.0  102.0  105.0    NaN  44.0\n",
       "44   王春月  118.0   82.0  112.0  312.0  45.0\n",
       "45   代明哲  101.0   91.0  115.0  307.0  46.0\n",
       "46   张开羽  112.0   90.0  104.0  306.0  47.0\n",
       "47   狄建译  109.0   68.0  126.0  303.0  48.0\n",
       "48   张家硕  107.0   67.0  129.0    NaN  49.0\n",
       "49    郭娜   94.0   98.0  104.0  296.0  50.0\n",
       "50    周坤  107.0   76.0  104.0  287.0  51.0\n",
       "51    洪禹  106.0  100.0   80.0  286.0  52.0\n",
       "52   王治超  105.0   95.0   82.0  282.0  53.0\n",
       "53   臧云飞  101.0   59.0  108.0  268.0  54.0\n",
       "54   袁茂哲   85.0   95.0   85.0  265.0  55.0\n",
       "55   丁婉艺   95.0   71.0   85.0  251.0  56.0\n",
       "56   于娇莹   97.0   76.0   71.0  244.0  57.0\n",
       "57   刘旭辉   99.0   87.0   44.0  230.0  58.0\n",
       "58   张宇婷   83.0   61.0   71.0  215.0  59.0\n",
       "59   黄明涛   87.0   77.0   43.0  207.0  60.0\n",
       "60   吕文卓   82.0   53.0   62.0  197.0  61.0\n",
       "61   王晟煜   79.0   49.0   64.0  192.0  62.0\n",
       "62   孙龙基   99.0   21.0   67.0  187.0  63.0\n",
       "63    赵森   90.0   29.0   64.0  183.0  64.0\n",
       "64   满朝升   78.0   45.0   47.0  170.0  65.0\n",
       "65   李忠浩   86.0   32.0   46.0  164.0  66.0\n",
       "66   侯禹志   75.0   23.0   34.0  132.0  67.0\n",
       "67   尹鸿涛   66.0   23.0   34.0  123.0  68.0"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "grade_empty.dropna(subset=['语文','数学','英语'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "79881538",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 填充\n",
    "#   通过均值填充\n",
    "#   1.求出各列中的均值\n",
    "#   2. 填充"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "4ac5569c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "      <th>总分</th>\n",
       "      <th>班名次</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>杨璐</td>\n",
       "      <td>131.0</td>\n",
       "      <td>143.0</td>\n",
       "      <td>144.0</td>\n",
       "      <td>418.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>王雪</td>\n",
       "      <td>131.0</td>\n",
       "      <td>135.0</td>\n",
       "      <td>144.0</td>\n",
       "      <td>410.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩林霖</td>\n",
       "      <td>127.0</td>\n",
       "      <td>139.0</td>\n",
       "      <td>142.0</td>\n",
       "      <td>408.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沙龙逸</td>\n",
       "      <td>106.0</td>\n",
       "      <td>148.0</td>\n",
       "      <td>136.0</td>\n",
       "      <td>407.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>李鉴学</td>\n",
       "      <td>106.0</td>\n",
       "      <td>135.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>401.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>赵森</td>\n",
       "      <td>90.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>183.0</td>\n",
       "      <td>64.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>满朝升</td>\n",
       "      <td>78.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>47.0</td>\n",
       "      <td>170.0</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>李忠浩</td>\n",
       "      <td>86.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>46.0</td>\n",
       "      <td>164.0</td>\n",
       "      <td>66.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>侯禹志</td>\n",
       "      <td>75.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>132.0</td>\n",
       "      <td>67.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>尹鸿涛</td>\n",
       "      <td>66.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>123.0</td>\n",
       "      <td>68.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名     语文     数学     英语     总分   班名次\n",
       "0    杨璐  131.0  143.0  144.0  418.0   1.0\n",
       "1    王雪  131.0  135.0  144.0  410.0   2.0\n",
       "2   韩林霖  127.0  139.0  142.0  408.0   3.0\n",
       "3   沙龙逸  106.0  148.0  136.0  407.0   4.0\n",
       "4   李鉴学  106.0  135.0  140.0  401.0   5.0\n",
       "..  ...    ...    ...    ...    ...   ...\n",
       "63   赵森   90.0   29.0   64.0  183.0  64.0\n",
       "64  满朝升   78.0   45.0   47.0  170.0  65.0\n",
       "65  李忠浩   86.0   32.0   46.0  164.0  66.0\n",
       "66  侯禹志   75.0   23.0   34.0  132.0  67.0\n",
       "67  尹鸿涛   66.0   23.0   34.0  123.0  68.0\n",
       "\n",
       "[68 rows x 6 columns]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# fillna指定列填充null值\n",
    "grade_empty['语文'].fillna(int(grade_empty['语文'].mean()),inplace=True)\n",
    "grade_empty['数学'].fillna(int(grade_empty['数学'].mean()),inplace=True)\n",
    "grade_empty['英语'].fillna(int(grade_empty['英语'].mean()),inplace=True)\n",
    "grade_empty"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
